package j2024.j202411;

import java.util.Arrays;
import java.util.Scanner;

public class j1109 {
    /**
     * 222. 完全二叉树的节点个数
     * 给你一棵 完全二叉树 的根节点 root ，求出该树的节点个数。
     *
     * 完全二叉树 的定义如下：在完全二叉树中，除了最底层节点可能没填满外，
     * 其余每层节点数都达到最大值，并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层，则该层包含 1~ 2h 个节点。
     */
    int ret = 0;
    public int countNodes(TreeNode root) {
        order(root);
        return ret;
    }
    public void order(TreeNode root){
        if(root==null) return;
        ret++;
        order(root.left);
        order(root.right);
    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),k = in.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt();
        }
        int[][] f = new int[n][k+1];
        int[][] g = new int[n][k+1];
        k = Math.min(k,n/2);
        for (int j = 0; j <= k; j++) {
            f[0][j] = g[0][j] = -0x3f3f3f3f;
        }
        f[0][0] = -p[0];g[0][0] = 0;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < k; j++) {
                f[i][j] = Math.max(g[i-1][j]-p[i],f[i-1][j]);
                g[i][j] =g[i-1][j];
                if(j>=1){
                    g[i][j] = Math.max(g[i][j],f[i-1][j-1]+p[0]);
                }
            }
        }
        int ret = 0;
        for (int i = 0; i <= k; i++) {
            ret = Math.max(ret,g[n-1][i]);
        }
        System.out.println(ret);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),x = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        Arrays.sort(arr);
        long ret = 0;
        int index = n-1-x;
        if(n<0){
            for (int i = 0; i < n; i++) {
                ret+=arr[i];
            }
        }else {
            ret+=arr[index];
            for (int i = index+1; i < n; i++) {
                ret+=(arr[i]-arr[index]);
            }
        }
        System.out.println(ret);
    }
}
